package cn.calm.xhtml.api.service;

import java.util.Map;

import cn.calm.xhtml.api.TemplateEngine;

public abstract class XhtmlContext {
	private TemplateEngine templateEngine;

	private ResponseWriter responseWriter;

//	public XhtmlContext(TemplateEngine templateEngine,
//			ResponseWriter responseWriter) {
//		super();
//		this.templateEngine = templateEngine;
//		this.responseWriter = responseWriter;
//	}

	public ResponseWriter getResponseWriter() {
		return responseWriter;
	}

	public void setResponseWriter(ResponseWriter responseWriter) {
		this.responseWriter = responseWriter;
	}

	public TemplateEngine getTemplateEngine() {
		return templateEngine;
	}

	public void setTemplateEngine(TemplateEngine templateEngine) {
		this.templateEngine = templateEngine;
	}
	public void setValueForExpress(String var, Object value){
		StringBuffer va=new StringBuffer();
		if(!var.startsWith("${")){
			va.append("${");
		}
		va.append(var);
		if(!var.endsWith("}")){
			va.append("}");
		}
		setValue(va.toString(), value);
	}
	public abstract void setValue(String var, Object value);

	public void removeValue(String var) {

		// getExpressContext().remove(var);
	}

	public void setAllValue(Map<String, Object> values) {
		for (Map.Entry<String, Object> e : values.entrySet()) {
			setValue(e.getKey(), e.getValue());
		}
	}

	public abstract Object getValue(String express) ;
}
